package com.listeningframework.boot.autoconfigure.template.thymeleaf.dialect;

import java.util.LinkedHashSet;
import java.util.Set;

import org.springframework.beans.factory.annotation.Autowired;
import org.thymeleaf.dialect.AbstractDialect;
import org.thymeleaf.processor.IProcessor;

/**
 * 
 * Listening Thymeleaf Dialect
 *
 * @author lixining
 * @version $Id: ListeningThymeleafDialect.java, v 0.1 2016年7月1日 下午6:44:20 lixining Exp $
 */
public class ListeningThymeleafDialect extends AbstractDialect {
    /**
     * Custom Listening Thymeleaf Processor
     */
    @Autowired(required = false)
    private ListeningThymeleafProcessor[] processors;

    @Override
    public String getPrefix() {
        return "ls";
    }

    /** 
     * @see org.thymeleaf.dialect.AbstractDialect#getProcessors()
     */
    @Override
    public Set<IProcessor> getProcessors() {
        Set<IProcessor> processorsSet = new LinkedHashSet<IProcessor>();
        if (processors == null || processors.length == 0) {
            return processorsSet;
        }
        for (ListeningThymeleafProcessor processor : processors) {
            processorsSet.add(processor);
        }
        return processorsSet;
    }

}
